<template>
	<view>
		<view class="mokuai" style="margin: 30rpx;padding: 20rpx;">
			<view class="border_bottom shenhe_list_container clear" v-for="(item,index) in list" :key="index" @tap="goinfo" :data-id="item.id">
				<view class="t_title left">
					<text style="color: #007AFF;" v-if="item.read_state==1">[已读]</text>
					<text style="color: #FF0000;" v-if="item.read_state==0">[未读]</text>
					{{item.title}}
				</view>
				<view class="right_time left">
				    {{item.create_at}}
				</view>
			</view>
			<image src="../../static/img/nodata.png" class="no-data" v-if="ishas3"  mode="widthFix"></image>
			<!-- <view class="border_bottom shenhe_list_container">
				<view class="clear shenhe-text" >
					<text class="left">客户姓名 </text>
					<text class="right blue_text">刘月月</text>
				</view>	
				
				<view class="clear shenhe-text" >
					<text class="left">申请时间 </text>
					<text class="right">2020-12-12</text>
				</view>
			</view> -->
			
		</view>
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	import {timestampToDate1} from '@/static/js/login.js';
	import MescrollUni from "@/components/mescroll-uni/uni-load-more.vue";
	var  _self,
	page = 1;
	export default {
		components: {
		    MescrollUni
		},
		data() {
			return {
				list:[],
				num:0,
				ishas3:false,
				loadingType: 0,
			    url:"",
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		onShow() {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}
			page = 1;
			_self = this;
			_self.getlist()
			
		},
		onLoad() {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}
			page = 1;
			_self = this;
			_self.getlist()
		},
		onPullDownRefresh() {
			page=1
			_self.loadingType=0;
		    this.getlist();   
		    setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom: function() {
			if (_self.loadingType != 0) {//loadingType!=0;直接返回
				return false;
			}
			_self.loadingType = 1;
			uni.showNavigationBarLoading();//显示加载动画
			page++;//每触底一次 page +1
			if(this.user.type==1){
				uni.request({
					url: httpPath.filePath+"/api.php/index/member/message_list/",
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,page:page},
					success: (res) => {
						if (res.data.result.length==0) {//没有数据
							_self.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return false;
						}
						for (let i = 0;i < res.data.result.length;i++) {
							_self.list.push(res.data.result[i]);
							
						}
						_self.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					}
				});
			}else{
				uni.request({
					url: httpPath.filePath+"/api.php/index/user/message_list",
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,page:page,user:this.user.user_id},
					success: (res) => {
						if (res.data.result.length==0) {//没有数据
							_self.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return false;
						}
						for (let i = 0;i < res.data.result.length;i++) {
							
							_self.list.push(res.data.result[i]);
							
						_self.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					   }
					}
				});
			}
		},
		methods: {
			goinfo(e){
				uni.navigateTo({
					url:"messageinfo?id="+e.currentTarget.dataset.id
				})
			},
			getlist(){
			    if(this.user.type==1){
					uni.request({
						url: httpPath.filePath+'/api.php/index/member/message_list/',
						method:'POST',
						header:{'content-type':'application/x-www-form-urlencoded'},
						data: {member_id:this.user.member_id,page:page},
						success: (res) => {
							console.log(res)
							if(res.data.code=="200"){
								// console.log(res.data.result.message)
								this.list=res.data.result;
								if(this.list.length==0){
									this.ishas3=true;
								}else{
									this.ishas3=false;
								}
							}else{
								if(this.list.length==0){
									this.ishas3=true;
								}else{
									this.ishas3=false;
								}
							}
							   
						}
					});
				}else{
					uni.request({
						url: httpPath.filePath+'/api.php/index/user/message_list',
						method:'POST',
						header:{'content-type':'application/x-www-form-urlencoded'},
						data: {member_id:this.user.member_id,user_id:this.user.user_id,page:page},
						success: (res) => {
							console.log(res)
							if(res.data.code=="200"){
								// console.log(res.data.result.message)
								this.list=res.data.result;
								if(this.list.length==0){
									this.ishas3=true;
								}else{
									this.ishas3=false;
								}
							}else{
								if(this.list.length==0){
									this.ishas3=true;
								}else{
									this.ishas3=false;
								}
							}
							   
						}
					});
				}

			},
	       //改变审核状态
		   changeindex(index,is_check){  
			   this.current=index;
			   this.is_check=is_check;
			   console.log(this.current)
		   } 
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	.t_title{font-size: 30rpx;color: #666;width: 60%;overflow: hidden;height: 40px;line-height: 40px;}
	.right_time{text-align: right;color: #999999;font-size: 28rpx;width: 40%;line-height: 40px;}
	.no-data{width: 40%;display: block;margin: auto;height: 160rpx;}
</style>
